
if($MM_Size $= "") $MM_Size = "8 8 8";
if($MM_Speed $= "") $MM_Speed = 500;

$MM_SizeUiNames["4 4 4"] = "8x Cube ";
$MM_SizeUiNames["8 8 8"] = "16x Cube ";

function fxDtsBrick::onTemplateGenerated(%brick, %client) {
	$InputTarget_["Self"] = %brick;
	$InputTarget_["Client"] = getBrickGroupFromObject(%brick).client;
	%brick.processInputEvent("onTemplateGenerated", fc(redo));
}
registerInputEvent("fxDTSBrick", "onTemplateGenerated", "Self fxDTSBrick");

if($MM_Init $= "") {
	registerOutputEvent("fxDTSBrick", "destroy", "", 1);
	$MM_Init = 1;
}
function fxDtsBrick::destroy(%brick, %client) {
	%brick.killBrick();
}

function serverCmdMaze(%c, %seed) {
	if(!%c.isAdmin) return;
	
	if(%seed $= "") %seed = getRandom(1, 10000);
	
	%sizeUiName = $MM_SizeUiNames[$MM_Size];
	if(%sizeUiName $= "") { talk("Error: No connector ui name for size \"" @ $MM_Size @ "\""); return; }
	
	luacall("BuildMazeFromBase", "maze_base", %seed, $MM_Size, %sizeUiName);
}

function serverCmdClearMaze(%c) {
	if(%c.isAdmin) {
		luacall("ClearMaze");
	}
}

function MazeUpdate() {
	luacall("MazeResume", $MM_Speed);
	
	cancel($MazeSched);
	$MazeSched = schedule(33, 0, MazeUpdate);
}
MazeUpdate();

function mmr() {
	exec("./server.cs");
}
